using System.Collections;
using System.Collections.Generic;
using QFramework;
using UnityEngine;

public class SaveSystem : AbstractSystem//保存系统,内部用 PlayerPrefs 实现；Keys 记录访问过的键名，支持在 OnGUI 调试查看。
{
    public void Save()
    {
        
    }
    public void Load()
    {

    }
    public HashSet<string> Keys = new HashSet<string>();
    public void SaveBool(string key,bool defaultValue=false)
    {
        Keys.Add(key);
        PlayerPrefs.SetInt(key,defaultValue?1:0);
    }
    public bool LoadBool(string key,bool defaultValue=false)
    {
        Keys.Add(key);
        return PlayerPrefs.GetInt(key, defaultValue ? 1 : 0) == 1;
    }
    public void SaveInt(string key,int defaultValue)
    {
        Keys.Add(key);
        PlayerPrefs.SetInt(key,defaultValue);
    }
    public int LoadInt(string key)
    {
        Keys.Add(key);
        return PlayerPrefs.GetInt(key);
    }
    public void SaveString(string key,string defaultValue)
    {
        Keys.Add(key);
        PlayerPrefs.SetString(key,defaultValue);
    }
    public string LoadString(string key)
    {
        Keys.Add(key);
        return PlayerPrefs.GetString(key);
    }
    protected override void OnInit()
    {
        ActionKit.OnGUI.Register(() =>//注册帧更新/UI调试回调；可以肉眼看到数据
        {
            if (Input.GetKey(KeyCode.L))
            {
                foreach (var item in Keys)
                {
                    GUILayout.Label(item+":"+PlayerPrefs.GetInt(item));
                    GUILayout.Label(item+":"+PlayerPrefs.GetString(item));
                    GUILayout.Label(item+":"+PlayerPrefs.GetFloat(item));
                }
            }
        });
    }
}
